package com.hspedu.newData.dmsxl.树.二叉树的遍历.层序遍历迭代法.队列;

import com.hspedu.newData.dmsxl.ds.TreeNode;
import org.junit.Test;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-07 
 * @Version: 1.0
 */

public class LC872叶子相似的树 {

    public boolean leafSimilar(TreeNode root1, TreeNode root2) {

        List<Integer> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();

        preorderTraversal(root1,list1);
        preorderTraversal(root2,list2);
        if (list1.size() != list2.size()) return false;

        for (int i = 0; i < list1.size(); i++) {
            int i1 = list1.get(i);
            int i2 = list2.get(i);
            if (i1 != i2){
                return false;
            }
        }
        return true;

    }

    public void preorderTraversal(TreeNode root,List<Integer> list){
        if (root == null) return;

        if (root.left == null && root.right == null){
            list.add(root.val);
        }
        preorderTraversal(root.left,list);
        preorderTraversal(root.right, list);

    }

    @Test
    public void test() {
        // 测试代码

        // 测试代码

        TreeNode t7 = new TreeNode(200);
        TreeNode t6 = new TreeNode(6);
        TreeNode t5 = new TreeNode(5);
//        TreeNode t4 = new TreeNode(4);
//        TreeNode t3 = new TreeNode(3,t6,t7);
//        TreeNode t2 = new TreeNode(2,t4,t5);
        TreeNode t1 = new TreeNode(1,t6,t7);

        leafSimilar(t1,t1);
        System.out.println("==========");

    }
}
